// --------------------------------------------------------------------------------------------------------------------
// <copyright company="Collaboris Ltd." file="IAction.cs">
//   Copyright (c) Collaboris Ltd. All rights Reserved.
// </copyright>
// <summary>
//   IAction represents unit of work that should
//   be performed taking IContext under consideration.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Collaboris.Saf.Engine
{
    using System;

    using Definitions;

    using Report;

    using SharePoint.Wss.Entities;

    public delegate void RefreshDynamicVariablesDelegate(object instance);
    
    /// <summary>
    /// IAction represents unit of work that should 
    /// be performed taking IContext under consideration.
    /// </summary>
    public interface IAction
    {
        RefreshDynamicVariablesDelegate RefreshDynamicVariables
        {
            set;
        }               
        
        /// <summary>
        /// Executes the Action.
        /// </summary>
        /// <param name="context">
        /// IContext containing context object for the Macro.
        /// </param>
        /// <returns>
        /// </returns>
        IProgressReport Do(SafContext context);

        /// <summary>
        /// Undoes the Action.
        /// </summary>
        /// <param name="context">
        /// IContext containing context object for the Macro.
        /// </param>
        /// <returns>
        /// </returns>
        IProgressReport Undo(SafContext context);


        /// <summary>
        /// Defines if the Macro should cease processing if an 
        /// exception is encountered during the 'Do' method for
        /// the action.
        /// </summary>
        bool StopOnDoException
        {
            get;
            set;
        }

        /*
        /// <summary>
        /// Defines if the Action should call AutoUndo
        /// if an Exception occurs in the "Do". If set 
        /// to True, this will cause the Undo to be called.
        /// </summary>
        bool AutoUndo
        {
            get;
            set;
        }
        */

        /// <summary>
        /// Defines if the Macro should cease processing if an 
        /// exception is encountered during the 'Undo' method for
        /// the action.
        /// </summary>
        bool StopOnUndoException
        {
            get;
            set;
        }

        /// <summary>
        /// Determines whether to Run the Do(IContext context)
        /// method.
        /// </summary>
        /// <remarks>
        /// This is useful if you want certain Actions to Run only the 'Undo()'
        /// but not the 'Do()'
        /// </remarks>
        bool DisableDo
        {
            get;
            set;
        }

        /// <summary>
        /// Determines whether to Run the Undo(IContext context)
        /// method.
        /// </summary>
        /// <remarks>
        /// This is useful if you want certain Actions to Run only the 'Do()'
        /// but not the 'Undo()'
        /// </remarks>
        bool DisableUndo
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the action unque ID.
        /// </summary>
        Guid ID
        {
            get;
            set;
        }

        /// <summary>
        /// Returns the Name of the Current Action
        /// </summary>
        /// <returns></returns>
        string Name
        {
            get;
            set;
        }

        /// <summary>
        /// Gets the Index of the Action specifying
        /// the position in the Macro.
        /// </summary>
        int Index
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets a condition that should evaluate 
        /// to True in order to run the 'Do' on the Action.
        /// </summary>
        /// <value>The condition.</value>
        bool DoCondition
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets a condition that should evaluate 
        /// to True in order to run the 'Undo' on the Action.
        /// </summary>
        /// <value>The condition.</value>
        bool UndoCondition
        {
            get;
            set;
        }
        
        /// <summary>
        /// Sets a condition that should evaluate 
        /// to True in order to run the 'Undo' or 'Do' on the Action.
        /// </summary>
        /// <remarks>
        /// This Condtion will be applied to both <see cref="DoCondition"/>
        /// and <see cref="UndoCondition"/>.
        /// If you want to apply the same condition to both Undo and Do, then
        /// this is a more short hand way to achieve this.
        /// </remarks>
        /// <value>The condition.</value>
        bool Condition
        {
            set;
        }         
                
        /// <summary>
        /// Gets or sets the parent macro.
        /// </summary>
        /// <value>The parent macro.</value>
        IMacro Macro
        {
            get;
            set;
        }


        /// <summary>
        /// Defines a List of POCO's that the Action uses
        /// to performs its task.
        /// </summary>
        EntityBase[] EntityList
        {
            get;
            set;
        }

        /// <summary>
        /// Returns a SAF Class Definition 
        /// </summary>
        SafClassDefinition Definition
        {
            get;
        }
    }
}